import React, { Suspense } from "react";
import { BrowserRouter, Route, Routes, Navigate } from "react-router-dom";
import routes from "./Router_config";

type Props = {};

const Router_view = (props: Props) => {
  const renderRoute = (routes: any) => {
    return routes.map((item: any, index: number) => {
      return (
        <Route
          key={index}
          path={item.path}
          element={
            item.to ? (
              <Navigate to={item.to}></Navigate>
            ) : (
              <item.element></item.element>
            )
          }
        >
          {item.children && renderRoute(item.children)}
        </Route>
      );
    });
  };
  return (
    <Suspense>
      <BrowserRouter>
        <Routes>{renderRoute(routes)}</Routes>
      </BrowserRouter>
    </Suspense>
  );
};

export default Router_view;
